		
	class CommonUtil
	{
		private static _disposed:boolean;
		public static dispose():void
		{
			if(CommonUtil._disposed)			
				return;
			
			CommonUtil._disposed = true;
			CommonUtil.__loopFuncObj = CommonUtil.__loopFuncVec = null;			
			clearInterval(CommonUtil.__timeId);			
		}

		public static loopTime:number;
		public static delta:number;
		public static frameRate:number;
		protected static __stage:Laya.Stage;
		private static __loopFuncVec:Function[];
		private static __loopFuncObj:any[];		
		private static __time:number;
		private static __timeId:number;
		public static Init(stage:Laya.Stage):void
		{
			CommonUtil._disposed = false;
			CommonUtil.__stage=stage;
			// CommonUtil.loopTime = CommonUtil.getTimer();
			CommonUtil.__loopFuncVec = new Array<Function>();
			CommonUtil.__loopFuncObj = new Array<any>();
			// CommonUtil.__stage.on(Laya.Event.FRAME, CommonUtil.__stage, CommonUtil.stageLoop);			
			// Laya.timer.frameLoop(1,null,CommonUtil.stageLoop);
			CommonUtil.loopTime = Date.now();			
			CommonUtil.frameRate = Laya.stage.frameRate == "fast"?60:30;
			CommonUtil.delta = Laya.stage.frameRate == "fast"?16:33;
			CommonUtil.__timeId = setInterval(function() {
				let t:number;
				t = Date.now();
				if(t - CommonUtil.loopTime >= CommonUtil.delta)
				{						
					CommonUtil.stageLoop(t);
				}				
			}, 0);
		}
		// public static getTimer():number
		// {
		// 	if(CommonUtil.__time == null)
		// 		CommonUtil.__time = Date.now();
		// 	return Date.now() - CommonUtil.__time;
		// }
		/**
		 * 添加val到舞台帧频执行列表中，ENTERFRAME事件触发时执行
		 * @param Function类型，无参数val();
		 * */
		public static addStageLoop(val:Function, thisObject:any):void
		{
			if(val == null)
			{
				throw(new Error("不能传入空函数！"));				
			}
			var ind:number = CommonUtil.__loopFuncVec.indexOf(val);
			if(ind == -1 || CommonUtil.__loopFuncObj[ind] != thisObject)
			{
				CommonUtil.__loopFuncVec.push(val);
				CommonUtil.__loopFuncObj.push(thisObject);
			}				
		}
		/**
		 * 从舞台帧频执行列表中删除val函数
		 * @param val 帧频函数
		 * */
		public static delStageLoop(val:Function, thisObject:any):void
		{			
			var len:number;
			len = CommonUtil.__loopFuncVec.length;
			while(--len>-1)
			{
				if(CommonUtil.__loopFuncVec[len] ==val && CommonUtil.__loopFuncObj[len] == thisObject)
				{
					CommonUtil.__loopFuncVec.splice(len, 1);
					CommonUtil.__loopFuncObj.splice(len, 1);
				}
			}
		}
		private static stageLoop(t:number):void
		{
			if(CommonUtil._disposed)return;
			CommonUtil.loopTime=t;
			var len:number;
			len=CommonUtil.__loopFuncVec.length;
			while(--len>-1)
			{
				if(len<CommonUtil.__loopFuncVec.length)
					CommonUtil.__loopFuncVec[len].call(CommonUtil.__loopFuncObj[len],CommonUtil.loopTime);
			}
		}
		/**帧频监听列表*/
		public static get loopFuncVec():Function[]
		{
			return CommonUtil.__loopFuncVec;
		}
		public static get loopFuncObj():any[]
		{
			return CommonUtil.__loopFuncObj;
		}
		//类似as3种的is类型判断，cls参数可以使用字符串，对于接口，在h5中只能使用字符串,继承链15层以内有效
		public static GYIs(obj,cls)
		{
			if(obj == null)return false;
			if(cls == "string")
				cls = String;
			else if(cls == "number")
				cls = Number;
			
			var proto;
			var c =0;
			proto = obj.__proto__;
			while(proto.constructor.name != "Object")
			{
				if(proto.constructor == cls)
					return true;
				proto = proto.__proto__;
				if(++c > 15)
					break;
			}
			return false;
		}

		/**下载文件 ,调用方法 download("save.txt","内容");
		 * @param obj 抛出事件的dom对象
		 * @param data ArrayBuffer 或者 Blob
		 * @param type mimeType {type:"image/png"}等
		*/
		public static download(name:string, data:any, type:any = null) {
			var urlObject:any = window.URL || window["webkitURL"] || window;

			var downloadData = CommonUtil.GYIs(data,Blob)?data:new Blob(CommonUtil.GYIs(data,Array)?data:[data],type);

			var save_link:any = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
			save_link.href = urlObject.createObjectURL(downloadData);
			save_link.download = name;
			this.dispatch_click(save_link);
		}
		/**主动抛出一个鼠标事件
		 * @param obj 抛出事件的dom对象
		*/
		public static dispatch_click(obj) {
			var ev = document.createEvent("MouseEvents");
			ev.initMouseEvent(
				"click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null
			);
			obj.dispatchEvent(ev);
		}
	
	}
